package org.xiaoyu.rpc.remoting.packet;

import lombok.Data;
import org.xiaoyu.rpc.seralization.support.SerializerAlgorithm;

/**
 * Created By Have
 * 2021/7/5 13:57
 */
@Data
public class AppResponse implements Packet {
    private Integer statusCode;
    private Result result;
    private String requestId;
    private String errorMessage;

    public AppResponse() {
    }

    public AppResponse(Integer statusCode, Result result, String requestId) {
        this.statusCode = statusCode;
        this.result = result;
        this.requestId = requestId;
    }

    public Object getData() {
        return result.getValue();
    }

    public boolean isSuccess() {
        return !result.hasException();
    }

    public Throwable getException() {
        return result.getException();
    }

    @Override
    public int getType() {
        return PacketType.RESPONSE_PACK;
    }

}
